package com.huahua.bigdata.spark.rdd.operate;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;

public class Spark04_Operate_transform_FlatMap_1 {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("spark");
        JavaSparkContext jsc = new JavaSparkContext(conf);

        JavaRDD<String> rdd = jsc.textFile("data/test.txt");

        JavaRDD<String> flatMapRDD = rdd.flatMap(
                line -> Arrays.asList(line.split(" ")).iterator()
        );
        flatMapRDD.collect().forEach(System.out::println);

        jsc.close();
    }
}
